-- 编辑代码过程中用到的插件
return {
	-- 自动括号
	{
		"windwp/nvim-autopairs",
		event = "InsertEnter",
		opts = {
			ignored_next_char = "[%w%.]", -- will ignore alphanumeric and `.` symbol
		},
	},

	-- 保存文件自动删除空白
	{
		"cappyzawa/trim.nvim",
		event = "BufWritePre",
		opts = {},
	},

	-- 保存文件更改历史，按 u 撤销保存关闭后再打开也有效
	-- leader + ut  查看的历史
	{
		"mbbill/undotree",
		keys = {
			{ "<leader>ut", "<cmd>UndotreeToggle<cr>", desc = "Toggle undo-tree" },
		},
		init = function()
			vim.cmd([[
      if has("persistent_undo")
         let target_path = expand('~/.undodir')

          " create the directory and any parent directories if the location does not exist.
          if !isdirectory(target_path)
              call mkdir(target_path, "p", 0700)
          endif

          let &undodir=target_path
          set undofile
      endif
      ]])
		end,
	},

	-- 快速注释，leader + /
	{
		"numToStr/Comment.nvim",
    -- stylua: ignore
    keys = {
      { "<leader>/", function() require("Comment.api").toggle.linewise.current() end,                 mode = "n", desc = "[Comment] Comment current line", },
      { "<leader>/", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", mode = "v", desc = "Comment current line",           },
      -- control + / keymappings
      { "<C-_>",     function() require("Comment.api").toggle.linewise.current() end,                 mode = "n", desc = "[Comment] Comment current line", },
      { "<C-_>",     "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", mode = "v", desc = "Comment current line",           },
    },
		config = true,
	},

	-- 复制到系统剪切板
	-- 已经有 clipboard.lua 暂时用不到，tmux 可以用
	-- {
	--   "ibhagwan/smartyank.nvim",
	--   event = { "BufWinEnter" },
	--   opts = {
	--     highlight = {
	--       timeout = 500, -- timeout for clearing the highlight
	--     },
	--     clipboard = {
	--       enabled = true,
	--     },
	--     osc52 = {
	--       silent = true, -- true to disable the "n chars copied" echo
	--     },
	--   },
	-- },

	-- 让光标更快跳转
	{
		"folke/flash.nvim",
		event = "BufReadPost",
		opts = {
			label = {
				rainbow = {
					enabled = true,
					shade = 1,
				},
			},
			modes = {
				char = {
					enabled = false,
				},
			},
		},
		keys = {
      -- stylua: ignore
    -- leader + f    然后输入要跳转的一个或多个字母，再目标字母实现跳转
      { "<leader>f", mode = { "n", "x", "o" }, function() require("flash").jump() end,              desc = "[Flash] Jump"              },
      -- stylua: ignore
    -- leader + F  按字母进入视图模式并选中对应区域，按 e 选中整个区域
      { "<leader>F", mode = { "n", "x", "o" }, function() require("flash").treesitter() end,        desc = "[Flash] Treesitter"        },
    -- leader + F     进入视图模式并选中
      -- stylua: ignore
      { "<leader>F", mode = { "o", "x" },      function() require("flash").treesitter_search() end, desc = "[Flash] Treesitter Search" },
      -- stylua: ignore
      { "<c-f>",     mode = { "c" },           function() require("flash").toggle() end,            desc = "[Flash] Toggle Search"     },
			-- leader + j 行间跳转
			{
				"<leader>j",
				mode = { "n", "x", "o" },
				function()
					require("flash").jump({
						search = { mode = "search", max_length = 0 },
						label = { after = { 0, 0 }, matches = false },
						jump = { pos = "end" },
						pattern = "^\\s*\\S\\?", -- match non-whitespace at start plus any character (ignores empty lines)
					})
				end,
				desc = "[Flash] Line jump",
			},
			{
				"<leader>k",
				mode = { "n", "x", "o" },
				function()
					require("flash").jump({
						search = { mode = "search", max_length = 0 },
						label = { after = { 0, 0 }, matches = false },
						jump = { pos = "end" },
						pattern = "^\\s*\\S\\?", -- match non-whitespace at start plus any character (ignores empty lines)
					})
				end,
				desc = "[Flash] Line jump",
			},
		},
	},

	-- NOTE:
	-- 高亮显示代码里的 comments
	-- 如 TODO、FIXME
	{
		"folke/todo-comments.nvim",
		dependencies = {
			"nvim-lua/plenary.nvim",
			"folke/snacks.nvim",
		},
		event = "VeryLazy",
    -- stylua: ignore
    keys = {
      ---@diagnostic disable-next-line: undefined-field
      { "<leader>st", function() require("snacks").picker.todo_comments({ keywords = { "TODO", "FIX", "FIXME", "BUG", "FIXIT", "HACK", "WARN", "ISSUE"  } }) end, desc = "[TODO] Pick todos (without NOTE)", },
      ---@diagnostic disable-next-line: undefined-field
      { "<leader>sT", function() require("snacks").picker.todo_comments() end, desc = "[TODO] Pick todos (with NOTE)", },
    },
		config = true,
	},

	-- 快速改符号
	-- leader sd "，删双引号
	-- leader sr " (，改成括号
	-- 视图模式下选中 sa "，加双引号

	{
		"echasnovsi/mini.surround",
		url = "git@github.com:echasnovski/mini.surround.git",
		version = "*",
		event = "BufReadPost",
		opts = { -- 所有配置项必须放在 opts 内部
			mappings = {
				add = "sa", -- Add surrounding in Normal and Visual modes
				delete = "sd", -- Delete surrounding
				find = "sf", -- Find surrounding (to the right)
				find_left = "sF", -- Find surrounding (to the left)
				highlight = "sh", -- Highlight surrounding
				replace = "sr", -- Replace surrounding
				update_n_lines = "sn", -- Update `n_lines`

				suffix_last = "l", -- Suffix to search with "prev" method
				suffix_next = "n", -- Suffix to search with "next" method
			},
		},
		config = true, -- 自动调用 setup(opts)
		keys = {
			-- Disable the vanilla `s` keybinding
			{ "s", "<NOP>", mode = { "n", "x", "o" } },
		},
	},

	{
		-- extend `a`/`i` textobjects
		"echasnovsi/mini.ai",
		url = "git@github.com:echasnovski/mini.ai.git",
		version = "*",
		event = "bufreadpost",
		config = true,
	},

	-- 视图模式下选中行
	-- mI，到每行开头修改
	-- mA，结尾
	{
		"jake-stewart/multicursor.nvim",
		branch = "1.0",
		event = "BufReadPost",
		keys = {
			-- Append/insert for each line of visual selections. Similar to block selection insertion.
			{
				"mh",
				function()
					require("multicursor-nvim").insertVisual()
				end,
				mode = "x",
				desc = "Insert cursors at visual selection",
			},
			{
				"ml",
				function()
					require("multicursor-nvim").appendVisual()
				end,
				mode = "x",
				desc = "Append cursors at visual selection",
			},
		},
		config = function()
			local mc = require("multicursor-nvim")
			mc.setup()

			-- Mappings defined in a keymap layer only apply when there are multiple cursors. This lets you have overlapping mappings.
			mc.addKeymapLayer(function(layerSet)
				-- Enable and clear cursors using escape.
				layerSet("n", "jk", function()
					mc.clearCursors()
				end)
			end)
		end,
	},

	-- 编程时间统计
	-- { "wakatime/vim-wakatime", lazy = false },
}
